Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
How do I split a string between / and "+" based on an outgoing link click, when there are colons in the actual URL?

JS Beginner here. I need to return itemName from a URL string, however, there are colons in the URL itself. When I split using ("""), I get an error that this won't work.

I have gotten this far, but I don't know what to change in my function to get the desired result. See the examples below:

Below is the URL:

 "https://www.website.com/items/item-name-1"+"?date_1=2022-10-05&date_2=2022-10-07&amount=2" 

Below you can see my code.

  
   if ({{Outgoing link}})
  var itemName= {{Click URL}};
      return itemName.split("/")[5].split(".")[0];
   
    
    console.log(extractSliceFromUrl(itemName))

   } 

This is my expected result:

 "item-name-1"

This is the actual result I get:

 "item-name-1"+"?date_1=2022-10-05&date_2=2022-10-07&amount=2"
 
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Would the following work?

It extracts whatever's between the last / and the first "+".

const url = "\"https://www.website.com/items/item-name-1\"+\"?date_1=2022-10-05&date_2=2022-10-07&amount=2\"";
console.log(url.substring(url.lastIndexOf('/') + 1, url.indexOf('"+"')));

about 4 years ago · Juan Pablo Isaza Relatório

0

I'd split by ? first:

const theURL = "https://www.website.com/items/item-name-1"+"?date_1=2022-10-05&date_2=2022-10-07&amount=2";

theURL.split("?")[0].split("/")[5].split(".")[0];

about 4 years ago · Juan Pablo Isaza Relatório

0

With the secondary result, you could just remove the ending using:

'"item-name-1"+"?date_1=2022-10-05&date_2=2022-10-07&amount=2"'.replace(/("[^"]+?")\+/, '$1')

Explanation of /("[^"]+?")\+/ (RegExp)

  • (...) catch the pattern (becomes the $1)
  • [^"] everything not "
  • +? get the shortest result possible
  • \+ escape + (+ is a special symbol, this will treat it as plain text)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda